package com.clt.ess.crypt;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

//import org.apache.http.HttpEntity;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.ClientProtocolException;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.ContentType;
//import org.apache.http.entity.mime.HttpMultipartMode;
//import org.apache.http.entity.mime.MultipartEntityBuilder;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.util.EntityUtils;

/**
 * �˺�������  ERROR ���� ESSB+�ļ�ID+ESSE
 * UploadFileToESSServer �ķ���ֵ�ĸ�ʽ��Ҫ�䶯�������޷��Ϳͻ��˽���
 * **/

public class HttpGetPostTest {
	public static String UploadFileToESSServer(InputStream ins,String sUrl,String sFileType,String sPosInfo){
		
		//�ϴ��ļ�
//		String sRet = inputStreamUpload(ins,sUrl);
//		System.out.println("inputStreamUpload Ret:" + sRet);
//		if(sRet.indexOf("ERROR") != -1)
//			return "";
//		if(sRet.indexOf("ESSB") == -1 || sRet.indexOf("ESSE") == -1)
//			return "";
//		sRet = sRet.substring(4, sRet.length() - 4);
//		//�����ļ�ǩ����Ϣ
//		sRet = SendFileInfo(sRet,sFileType,sPosInfo,sUrl);
//		System.out.println("SendFileInfo Ret:" + sRet);
//		if(sRet.indexOf("ERROR") != -1)
//			return "";
//		if(sRet.indexOf("ESSB") == -1 || sRet.indexOf("ESSE") == -1)
//			return "";
//		sRet = sRet.substring(4, sRet.length() - 4);
//		return sRet;
		return "";
		
	}
	
	/**
	 * �˺�������  ERROR ���� ESSB+�ļ�ID+ESSE
	 * **/
	private static String SendFileInfo(String sFileID,String sFileType,String sPosInfo,String sUrl){
//		Map<String, String> params = new HashMap<String, String>();  
//		params.put("FID", sFileID); 
//		if(sPosInfo == null)
//			sPosInfo = "";
//		params.put("POSINFO", sPosInfo); 
//		params.put("FILETYPE", sFileType); 
//		
//	//	System.out.println("URL:" + sUrl);
//		
//		
//		//Map<String, String> headMap;
//	//	HttpClientUtils.getInstance().httpPost(url, paramsMap, headMap)
//		
//		
//		return HttpClientUtils.getInstance().httpPost(sUrl, params);  
		return "";
		
	}
	
	/**
	 * �˺�������  ERROR ���� ESSB+�ļ�ID+ESSE
	 * **/
    private static String inputStreamUpload(InputStream inputStream,String sUrl) {
//        //����HttpClient����
//        CloseableHttpClient client = HttpClients.createDefault();
//        //����POST����   �����ַ�����Ϊ�Լ��ġ�
//        //1)
//        HttpPost post = new HttpPost(sUrl);
//        try {
//            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
//            builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
//            builder.addBinaryBody("uploadFile", inputStream, ContentType.create("multipart/form-data"), "tempfilename");
//            HttpEntity entity = builder.build();  
//            post.setEntity(entity);            
//            //��������
//            HttpResponse response = client.execute(post);
//            entity = response.getEntity();
//            if (entity != null) {
//            	byte[] bytes = EntityUtils.toByteArray(entity);  
//            	System.out.println(new String(bytes));
//            	return new String(bytes);
//            }
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (ClientProtocolException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }finally {
//        		
//        }
        return "ERROR";
    }
}
